import { Module } from '@nestjs/common';
import { GirlModule } from './girl/girl.module';
import { AuthModule } from './auth/auth.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import { APP_GUARD } from '@nestjs/core';
import { jwtAuthGuard } from './utils/jwt-auth.grard';
import { UploadModule } from './upload/upload.module';

@Module({
  imports: [
    GirlModule,
    AuthModule,
    TypeOrmModule.forRoot({
      type: 'mysql',
      host: 'localhost',
      port: 3306,
      username: 'root',
      password: '12345678',
      database: 'nestjs',
      synchronize: true,
      retryDelay: 500, //重试连接数据库间隔
      retryAttempts: 10, //重试连接数据库的次数
      autoLoadEntities: true, //如果为true,将自动加载实体 forFeature()注册的每个实体都自己动加载
    }),
    UploadModule,
  ],
  controllers: [],
  // 注册为全局守卫
  providers: [
    {
      provide: APP_GUARD,
      useClass: jwtAuthGuard,
    },
  ],
})
export class AppModule {}
